package cn.xfdzx.android.apps.shop.presenter;

import cn.xfdzx.android.apps.shop.base.BasePresenter;
import cn.xfdzx.android.apps.shop.bean.LicenseImgBeen;
import cn.xfdzx.android.apps.shop.bean.OneBeen;
import cn.xfdzx.android.apps.shop.contract.ShopInContract;
import cn.xfdzx.android.apps.shop.model.ShopInModel;
import cn.xfdzx.android.apps.shop.net.RxScheduler;
import io.reactivex.functions.Consumer;

/**
 * @author azheng
 * @date 2018/6/4.
 * Description：
 */
public class LoginPresenter extends BasePresenter<ShopInContract.View> implements ShopInContract.Presenter {

    private ShopInContract.Model model;

    public LoginPresenter() {
        model = new ShopInModel();
    }


    @Override
    public void oneType(String pid, String index_status) {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.oneType(pid, index_status)
                .compose(RxScheduler.<OneBeen>Flo_io_main())
                .as(mView.<OneBeen>bindAutoDispose())
                .subscribe(new Consumer<OneBeen>() {
                    @Override
                    public void accept(OneBeen bean) throws Exception {
                        mView.oneTypeSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }

    @Override
    public void licenseImg(String licenseImg) {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.licenseImg(licenseImg)
                .compose(RxScheduler.<LicenseImgBeen>Flo_io_main())
                .as(mView.<LicenseImgBeen>bindAutoDispose())
                .subscribe(new Consumer<LicenseImgBeen>() {
                    @Override
                    public void accept(LicenseImgBeen bean) throws Exception {
                        mView.oneLicenseImgSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }
}
